import java.util.Stack;

class MinStack {
    private Stack<Integer> s1 = new Stack<>();
    private Stack<Integer> minStack = new Stack<>();

    public MinStack() {

    }
    
    public void push(int val) {
        s1.push(val);
        if (minStack.isEmpty()) {
            minStack.push(val);
        } else {
            int x1 = minStack.peek();
            if (val <= x1) {
                minStack.push(val);
            }
        }
    }
    
    public void pop() {
        int x = s1.pop();
        if (x == minStack.peek()) {
            minStack.pop();
        }
    }
    
    public int top() {
        return s1.peek();
    }
    
    public int getMin() {
        return minStack.peek();
    }
}